package com.easymeeting.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.easymeeting.entity.enums.PageSize;
import com.easymeeting.entity.query.TbOrderQuery;
import com.easymeeting.entity.po.TbOrder;
import com.easymeeting.entity.vo.PaginationResultVO;
import com.easymeeting.entity.query.SimplePage;
import com.easymeeting.mappers.TbOrderMapper;
import com.easymeeting.service.TbOrderService;
import com.easymeeting.utils.StringTools;


/**
 *  业务接口实现
 */
@Service("tbOrderService")
public class TbOrderServiceImpl implements TbOrderService {

	@Resource
	private TbOrderMapper<TbOrder, TbOrderQuery> tbOrderMapper;

	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<TbOrder> findListByParam(TbOrderQuery param) {
		return this.tbOrderMapper.selectList(param);
	}

	/**
	 * 根据条件查询列表
	 */
	@Override
	public Integer findCountByParam(TbOrderQuery param) {
		return this.tbOrderMapper.selectCount(param);
	}

	/**
	 * 分页查询方法
	 */
	@Override
	public PaginationResultVO<TbOrder> findListByPage(TbOrderQuery param) {
		int count = this.findCountByParam(param);
		int pageSize = param.getPageSize() == null ? PageSize.SIZE15.getSize() : param.getPageSize();

		SimplePage page = new SimplePage(param.getPageNo(), count, pageSize);
		param.setSimplePage(page);
		List<TbOrder> list = this.findListByParam(param);
		PaginationResultVO<TbOrder> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(), page.getPageTotal(), list);
		return result;
	}

	/**
	 * 新增
	 */
	@Override
	public Integer add(TbOrder bean) {
		return this.tbOrderMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Integer addBatch(List<TbOrder> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.tbOrderMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增或者修改
	 */
	@Override
	public Integer addOrUpdateBatch(List<TbOrder> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.tbOrderMapper.insertOrUpdateBatch(listBean);
	}

	/**
	 * 多条件更新
	 */
	@Override
	public Integer updateByParam(TbOrder bean, TbOrderQuery param) {
		StringTools.checkParam(param);
		return this.tbOrderMapper.updateByParam(bean, param);
	}

	/**
	 * 多条件删除
	 */
	@Override
	public Integer deleteByParam(TbOrderQuery param) {
		StringTools.checkParam(param);
		return this.tbOrderMapper.deleteByParam(param);
	}

	/**
	 * 根据Id获取对象
	 */
	@Override
	public TbOrder getTbOrderById(Integer id) {
		return this.tbOrderMapper.selectById(id);
	}

	/**
	 * 根据Id修改
	 */
	@Override
	public Integer updateTbOrderById(TbOrder bean, Integer id) {
		return this.tbOrderMapper.updateById(bean, id);
	}

	/**
	 * 根据Id删除
	 */
	@Override
	public Integer deleteTbOrderById(Integer id) {
		return this.tbOrderMapper.deleteById(id);
	}
}